<?php
/**
 * Created by PhpStorm.
 * User: sofu
 */
require './Mediway/SignGenerator.php';
require './Mediway/AESDataMcrypt.php';
require './Mediway/GatewayManager.php';

use Mediway\GatewayManager;
use Mediway\SignGenerator;
use Mediway\AESDataMcrypt;

$appId = '52891cfd-4474-11e9-ba95-525400d51ea6';
$token = 'LDk4OTAyNDk2NTEsNzMxYTVkZjYsNmFlMTVkMDA0NTI1LTU5YWItOWUxMS00NzQ0LWRmYzE5ODI1LDE1Njk0MTM3ODk=';

$signGenerator = new SignGenerator('md5', 'huanzheduan12345');
$mcrypt = new AESDataMcrypt('aes-128-cbc', 'huanzheduan12345', '0102030405060708');
$msgr = new GatewayManager('http://localhost:9005', $appId, $token, $signGenerator, $mcrypt);

$bizContent = [
    "name"=>"hello"
];

list($code, $duration, $headers, $body) = $msgr->post('patient.hospital.rest.test', $bizContent, 'v1.0');

echo $body;
$data = json_decode($body, true)['data'] ?? '';
// 解密
if ($data) {
    echo PHP_EOL . PHP_EOL;
    $data = $mcrypt->decrypt($data);
    $parseData = json_decode($data, true);
    if(json_last_error()){
        echo $data;
    }else{
        echo json_encode($parseData, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE);
    }
}


